package pcd;

import java.net.URL;

import com.avetti.commerce.integration.pcd.ws.CFCInvocationException;
import com.avetti.commerce.integration.pcd.ws.UtilityServiceCfcSoapBindingStub;
import com.avetti.commerce.integration.pcd.ws.UtilityService_ServiceLocator;
import com.avetti.commerce.integration.pcd.ws.datatypes.Client;
import com.avetti.commerce.integration.pcd.ws.datatypes.RPCDefault;

public class PCDTest {
	
	private String test_util_http="http://pcdtest.palmcoastd.com/pcdtest/api/UtilityService.cfc";
	private String test_util_https="https://pcdtest.palmcoastd.com/pcdtest/api/UtilityService.cfc";
	
	private String live_util_https="https://ssl.palmcoastd.com/pcd/api/UtilityService.cfc";
	
	private String url_inuse=test_util_http;
	
	/**
	 * axis JAX-RPC
	 * @param args
	 * @throws Exception
	 */
    public void axis_echo(String[] args) throws Exception {
    	
    	
    	UtilityServiceCfcSoapBindingStub binding=null;
        try {
            binding = (UtilityServiceCfcSoapBindingStub)
                          new UtilityService_ServiceLocator().getUtilityServiceCfc(new URL(url_inuse));
        }
        catch (javax.xml.rpc.ServiceException jre) {
            jre.printStackTrace();
        }

        // Time out after a minute
        //binding.setTimeout(60000);

        // Test operation
        try {
            RPCDefault value = null;
            value = binding.echo("axis JAX-RPC echo call");
            
            outResult(value);
        }
        catch (CFCInvocationException e1) {
            e1.printStackTrace();
        }
            // TBD - validate results
       
    }
    
    public void axis_check(String[] args) throws Exception {
    	UtilityServiceCfcSoapBindingStub binding=null;
        try {
            binding = (UtilityServiceCfcSoapBindingStub)
                          new UtilityService_ServiceLocator().getUtilityServiceCfc(new URL(url_inuse));
        }
        catch (javax.xml.rpc.ServiceException jre) {
            jre.printStackTrace();
        }

        // Time out after a minute
        //binding.setTimeout(60000);

        // Test operation
        try {
            RPCDefault value = null;
            Client c= new Client("xx","xx","xx","xx");
            value = binding.checkCredentials(c);
            com.avetti.commerce.integration.pcd.ws.datatypes.Error[] errs=value.getErrors();

            outResult(value);

        }
        catch (CFCInvocationException e1) {
            e1.printStackTrace();
        }
            // TBD - validate results
       
    }
    
    private void outResult(RPCDefault d) {
		System.out.println("Data>" + d.getData());
		System.out.println("Request>" + d.getRequest());
		System.out.println("Success>" + d.getSuccess());
		System.out.println("Errors>");
		for (int i = 0; i < d.getErrors().length; i++) {
			System.out.println("  " + d.getErrors()[i].getErrorId() + "<==>"
					+ d.getErrors()[i].getErrorDesc());
		}
	}
    
    public static void out(Object obj){
    	System.out.println("!!!!!!"+obj);
    }
    
    public static void test(){
    	try{
    		out("in try()");
    		return;
    	}catch(Exception e){
    		out("in exception");
    	}finally{
    		out("in finally()");
    	}
    }
    

    public static void main(String[] args) throws Exception {
    	out("before call");
    	test();
    	out("after call");
        /*
    	PCDTest cst=new PCDTest();
        cst.axis_check(args);
        System.out.println("");
        cst.axis_echo(args);
        
        cst.xfire_echo_orig();
        */
    }
}
